﻿using System.Web.Mvc;
using rosata.Areas.Admin.Filters;
using rosata.Providers.Session;

namespace rosata.Areas.Admin.Controllers
{
    public class IndexController : Controller
    {
        private readonly IUserSessionProvider _userSessionProvider;

        public IndexController(IUserSessionProvider userSessionProvider)
        {
            _userSessionProvider = userSessionProvider;
        }

        [CheckAdminFilter]
        public ActionResult Index()
        {
            return View("IndexAdmin");
        }

        public ActionResult Login()
        {
            return View("Login");
        }

        public ActionResult DoLogin(string username, string password)
        {
            //le stringhe devono essere bonificate!!
            bool isLoggedAdmin = _userSessionProvider.LogAdmin(username, password);

            if (!isLoggedAdmin)
                return RedirectToAction("Login");

            ////faccio vedere all'utente l'elenco delle 
            return View("IndexAdmin");
        }

    }
}
